package org.example.admin.manage.controller;

import org.example.admin.manage.dto.LoginReturn;
import org.example.admin.manage.service.SysAdminService;
import org.example.commons.entity.SysAdmin;
import org.example.commons.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * author 陈伯瑞
 * date 2020/6/4 0004 15:05
 * version 1.0
 **/
@RestController
@RequestMapping("/api/admin")
public class LoginCheckController {
    @Autowired
    SysAdminService sysAdminService;

    /**
     *
     */
    @GetMapping("/login")
    public ResultVO login(@RequestParam("account") String username, @RequestParam("pwd") String password) {
        SysAdmin admin = sysAdminService.findByName(username);
        if (admin != null) {
            if (admin.getPassword().equals(password)) {
                LoginReturn loginReturn = new LoginReturn(admin);
                System.out.println(ResultVO.success(loginReturn).toString());
                return ResultVO.success(loginReturn);
            }
        }
        return ResultVO.error("验证错误");
    }
}
